package com.itheima.web.listener;

import com.itheima.autoconfig.huanxin.HuanXinTemplate;
import com.itheima.autoconfig.huawei.HuaWeiUGCTemplate;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

/**
 * @author Guanxing
 * @date 2021/10/7
 */
@Component
@RocketMQMessageListener(consumerGroup = "movement",topic = "tanhua-movement")
public class MovementListener implements RocketMQListener<String> {

    @Reference
    private MovementService movementService;

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;

    @Override
    public void onMessage(String movementId) {
        System.out.println("开始审核数据");
        //查询数据
        Movement movement = movementService.findMovementByMovementId(movementId);
        //审核动态文字及图片
        boolean flag1 = huaWeiUGCTemplate.textContentCheck(movement.getTextContent());
        boolean flag2 = huaWeiUGCTemplate.imageContentCheck(movement.getMedias().toArray(new String[]{}));
        if (flag1 && flag2) {
            movement.setState(0);
        } else {
            movement.setState(0);
        }
        movementService.updateMovement(movement);
    }
}
